package chapter3.No3_1_等待和通知机制.l通过管道进行线程间通信_字符流;

import java.io.IOException;
import java.io.PipedReader;
import java.io.PipedWriter;

/**
 * 管道进行线程间通信：字符流
 *  1.  PipedReader 读取
 *      PipedWriter 写入
 * Created by Administrator on 2016/11/20.
 */
public class Main {

    public static void main(String[] args) throws InterruptedException, IOException {
        PipedReader pipedReader = new PipedReader();
        PipedWriter pipedWriter = new PipedWriter();
        ReadData readData = new ReadData();
        WriteData writeData = new WriteData();

        ThreadRead threadRead = new ThreadRead(readData, pipedReader);
        ThreadWrite threadWrite = new ThreadWrite(writeData, pipedWriter);
        // 建立连接
        pipedReader.connect(pipedWriter);

        threadRead.start();

        Thread.sleep(2000);
        threadWrite.start();

    }

}
